package com.park.platform.service.impl;

import com.park.common.bean.MemberInputView;
import com.park.common.bean.PageBean;
import com.park.common.util.StrUtil;
import com.park.platform.dao.IBaseDao;
import com.park.platform.service.IDictService;
import com.park.platform.service.IMemberService;
import com.park.platform.service.IOperatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl extends BaseService implements IMemberService {
	
	@Autowired
	private IBaseDao baseDao;
	
	@Autowired
	private IDictService dictService;
	
	@Autowired
	private IOperatorService operatorService;
	
	@Override
	public PageBean getUserMembers(MemberInputView memberInputView) {
		String memberMobile = memberInputView.getMemberMobile();
		String memberName = memberInputView.getMemberName();

		StringBuilder headSql = new StringBuilder("SELECT u.*, (SELECT COUNT(1) FROM user_sign s WHERE s.id = u.id) signCount");
		StringBuilder bodySql = new StringBuilder(" FROM user_operator u");
		bodySql.append(" JOIN system_role_operator r ON(u.id = r.id)");
		StringBuilder whereSql = new StringBuilder(" WHERE r.roleId = ").append(memberInputView.getRoleId());
		if(StrUtil.isNotBlank(memberMobile)){
			whereSql.append(" AND u.operatorMobile = :memberMobile");
		}
		if(StrUtil.isNotBlank(memberName)){
			whereSql.append(" AND u.operatorName LIKE :memberName");
			memberInputView.setMemberName(memberName+"%");
		}
		whereSql.append(" ORDER BY u.createTime DESC");
		PageBean pageBean = super.getPageBean(headSql, bodySql, whereSql, memberInputView);
		return pageBean;
	}
	
}



